package com.cheyunkeji.er.adapter.evaluate;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.adapter.MyBaseAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/7/27 23:09.
 *
 * 侧滑导航菜单适配器
 *
 */

public class MenuNavigatorAdapter extends MyBaseAdapter {

    private int[] selectedImgs = new int[]{R.drawable.er_icon_1_pressed, R.drawable.er_icon_2_pressed, R.drawable.er_icon_3_pressed, R.drawable.er_icon_4_pressed, R.drawable.er_icon_5_pressed, R.drawable.er_icon_6_pressed, R.drawable.er_icon_7_pressed, R.drawable.er_icon_8_pressed,
            R.drawable.er_icon_9_pressed, R.drawable.er_icon_10_pressed, R.drawable.er_icon_11_pressed, R.drawable.er_icon_12_pressed, R.drawable.er_icon_13_pressed, R.drawable.er_icon_14_pressed, R.drawable.er_icon_15_pressed,};

    private int[] normalImgs = new int[]{R.drawable.er_icon_1_normal, R.drawable.er_icon_2_normal, R.drawable.er_icon_3_normal, R.drawable.er_icon_4_normal, R.drawable.er_icon_5_normal, R.drawable.er_icon_6_normal, R.drawable.er_icon_7_normal,
            R.drawable.er_icon_8_normal, R.drawable.er_icon_9_normal, R.drawable.er_icon_10_normal, R.drawable.er_icon_11_normal, R.drawable.er_icon_12_normal, R.drawable.er_icon_13_normal, R.drawable.er_icon_14_normal, R.drawable.er_icon_15_normal,};

    private int[] queImgs = new int[]{R.drawable.er_icon_1_que, R.drawable.er_icon_2_que, R.drawable.er_icon_3_que, R.drawable.er_icon_4_que, R.drawable.er_icon_5_que, R.drawable.er_icon_6_que, R.drawable.er_icon_7_que,
            R.drawable.er_icon_8_que, R.drawable.er_icon_9_que, R.drawable.er_icon_10_que, R.drawable.er_icon_11_que, R.drawable.er_icon_12_que, R.drawable.er_icon_13_que, R.drawable.er_icon_14_que, R.drawable.er_icon_15_que,};

    private int[] mustMenu = new int[]{0,1,3,14};

    private int mSelect = 0;
    private List<Integer> iroute = new ArrayList<Integer>();

    public void changeSelected(int position) {
        if (position != mSelect) {
            mSelect = position;

            if (iroute.size()!=0 &&iroute.get(position)==0){
                iroute.set(position, 1);
            }
            notifyDataSetChanged();
        }
    }

    public MenuNavigatorAdapter(ArrayList<String> dataList, Context context ) {
        super(dataList, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.er_menu_navigator_lv_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (mSelect == position) {
            holder.rlContainer.setBackgroundResource(R.color.auction_status_bar);
            holder.tvItem.setTextColor(Color.WHITE);
            holder.iv.setImageResource(selectedImgs[position]);
            holder.ivArrow.setImageResource(R.drawable.arrow_pressed);
        } else {
            holder.rlContainer.setBackgroundColor(Color.parseColor("#ffffff"));
            holder.tvItem.setTextColor(Color.BLACK);
            holder.iv.setImageResource(normalImgs[position]);
            holder.ivArrow.setImageResource(R.drawable.arrow_normal);
            //设置缺少条目
            if (iroute.size() == 0 || (iroute.size()!=0 &&iroute.get(position)==0)){
                holder.rlContainer.setBackgroundColor(Color.parseColor("#ffecd9"));
                holder.tvItem.setTextColor(Color.parseColor("#ff6c60"));
                holder.iv.setImageResource(queImgs[position]);
                holder.ivArrow.setImageResource(R.drawable.arrow_red);
            }
        }
        for (int i = 0; i < mustMenu.length; i++) {
            if(mustMenu[i] == position){
                holder.tv_must.setVisibility(View.VISIBLE);
            }
        }

        holder.tvItem.setText((String) dataList.get(position));

        return convertView;
    }

    public void setDefect(List<Integer> getIroute) {
        this.iroute = getIroute;
        notifyDataSetChanged();
    }

    static class ViewHolder {

        @BindView(R.id.iv)
        ImageView iv;
        @BindView(R.id.tv_item)
        TextView tvItem;
        @BindView(R.id.tv_must)
        TextView tv_must;
        @BindView(R.id.rl_container)
        RelativeLayout rlContainer;
        @BindView(R.id.iv_arrow)
        ImageView ivArrow;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
